/*
 * Copyright (c) 2020 libinal's testing project.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * imitations under the License.
 */

package com.platform.comm.util.spel;

import java.util.Map;

/**
 * Description: SQL模版方法
 *
 * @author libinal created on 2020/3/17.
 */
public final class SqlTpl {
    public static String hasThenEq(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s %s :%s", column, "=", key) : "";
    }

    public static String hasThenGt(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s %s :%s", column, ">", key) : "";
    }

    public static String hasThenLt(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s %s :%s", column, "<", key) : "";
    }

    public static String hasThenLe(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s %s :%s", column, "<=", key) : "";
    }

    public static String hasThenGe(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s %s :%s", column, ">=", key) : "";
    }

    public static String hasThenNe(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s %s :%s", column, "!=", key) : "";
    }

    public static String hasThenLike(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s like '%%:%s%%'", column, key) : "";
    }

    public static String hasThenBetween(Map<String, Object> map, String key, String column) {
        return map.containsKey(key) ? String.format(" AND %s between :%s AND :%s", column, key + "Start", key + "End") : "";
    }
}
